#include <stdio.h>
#include <stdlib.h>

int main()
{
  pid_t pid = fork();
  if(pid == 0) {
    int cnt = 5;
    while(cnt) {
      printf("child[%d] is running : cnt is : %d\n", getpid(), cnt);
      cnt--;
      sleep(1);
    }
    exit(1);
  }
  sleep(10);
  printf("parent begin running\n");
  int status = 0;
  pid_t ret = waitpid(pid, &status, 0);
  if(ret > 0) {
    if(WIFEXITED(status)){
      printf("exit code: %d\n", WEXITSTATUS(status));
    }
  }
  else {
    printf("failed\n");
  }
}
